/***************************************************************************
 *   Copyright (C) 2008 by Thomas Richards   *
 *   thomi@colon   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef PROJECT_H
#define PROJECT_H

#include <QObject>
#include <QDir>
#include <QTimer>
#include <QFileInfo>
#include <QTemporaryFile>

class Plugin;

/**
	\author Thomas Richards <thomi@colon>
	\brief Projects handle all of the top-level work of scanning source files. They are run by the central scheduler.
*/
class Project : public QObject
{
Q_OBJECT
public:
    Project(const QDir &projectDir, QObject *parent = 0);

    ~Project();
	
	void createNewProject();
	
	
	// project state will be one of the above:
	enum tProjectState
	{
		STATE_INITIAL,			// project is idle - not running
  		STATE_WAIT_COPY,		// waiting for copy plugin to finish
		STATE_WAIT_BROWSE,		// waiting for browser plugin to complete
  		STATE_SCANNING,
		STATE_OUTPUT,
		STATE_DONE
	};
	
public slots:
	//
	// starts the project running.
	void runProject(const QString &strProjectFile);
	
signals:
	//sent whenever the project state changes.
	void stateChanged(Project::tProjectState nState);
	
private slots:
	// periodic tick - do stuff here:
	void tick();
	
private:
	// base directory for project:
	QDir m_projectDir;
	// current project state:
	tProjectState m_nCurrentState;
	// tick timer:
	QTimer m_tickTimer;

	// getter plugin to use:
	QString m_strGetter;
	// browser plugin to use:
	QString m_strBrowser;
	// output plugin to use:
	QString m_strOutput;
	// list of scanner plugins to use:
	QStringList m_slScanners;
	// project file:
	QFileInfo m_projectFile;
	// list of files we need to scan:
	QList<QByteArray> m_slFilesToScan;
	
	QTemporaryFile m_outputFile;
	
	// copy plugin ptr. we store this so we can access it across multiple ticks.
	Plugin *m_pCopyPlugin;
	Plugin *m_pBrowserPlugin;
	
	void setState(tProjectState newState);
};

#endif
